<?php
use think\facade\Db;
use app\admin\model\AuthRule as AuthRuleModel;

if (!AuthRuleModel::where('title', '问卷管理')->count()) {

    $parent_id = AuthRuleModel::query()->create([
        'parent_id'    => 0,
        'title'        => '问卷管理',
        'url'          => '#',
        'method'       => 'OPTIONS',
        'slug'         => 'survey'
    ]);
    $parent_id_1 =  AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '问卷主题',
        'url'          => 'survey_theme',
        'method'       => 'GET',
        'slug'         => 'survey.theme'
    ]);
    $parent_id_2 =  AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '题目管理',
        'url'          => 'survey_question_index',
        'method'       => 'GET',
        'slug'         => 'survey.survey_question_index'
    ]);
    $parent_id_3 =  AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '答题记录',
        'url'          => 'survey_record',
        'method'       => 'GET',
        'slug'         => 'survey.record'
    ]);

    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_3->id,
        'title'        => '答题导出',
        'url'          => 'survey_export',
        'method'       => 'POST',
        'slug'         => 'survey.export'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '主题详情',
        'url'          => 'survey_theme_detail',
        'method'       => 'POST',
        'slug'         => 'survey.theme_detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '添加主题',
        'url'          => 'survey_theme_create',
        'method'       => 'POST',
        'slug'         => 'survey.theme_create'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '编辑主题',
        'url'          => 'survey_theme_edit',
        'method'       => 'POST',
        'slug'         => 'survey.theme_edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '删除主题',
        'url'          => 'survey_theme_delete',
        'method'       => 'POST',
        'slug'         => 'survey.theme_delete'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '题目导入',
        'url'          => 'survey_question_import',
        'method'       => 'POST',
        'slug'         => 'survey.survey_question_import'
    ]);

    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '题目详情',
        'url'          => 'survey_question_detail',
        'method'       => 'POST',
        'slug'         => 'survey.question_detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '添加题目',
        'url'          => 'survey_question_create',
        'method'       => 'POST',
        'slug'         => 'survey.question_create'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '编辑题目',
        'url'          => 'survey_question_edit',
        'method'       => 'POST',
        'slug'         => 'survey.question_edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '删除题目',
        'url'          => 'survey_question_delete',
        'method'       => 'POST',
        'slug'         => 'survey.question_delete'
    ]);

}

